package Filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebFilter(filterName = "loginFilter1")
public class loginFilter1 implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse res = (HttpServletResponse) resp;

        String state = req.getParameter("state");
        String token = req.getParameter("token");

//        if(token == null && !state.equals("STATE")){
//            res.sendRedirect("https://cas.dgut.edu.cn?appid=javaee&state=STATE");
//            chain.doFilter(req, res);
//        }
        HttpSession session = req.getSession(true);
        session.setAttribute("token", token);
        chain.doFilter(req, res);
    }
    @Override
    public void init(FilterConfig config) throws ServletException {
    }

    @Override
    public void destroy() {
    }

}
